From afae9f3f8d4f45a6e419d57f371f5157070d7c8e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 9 Aug 2016 16:11:20 +0300 Subject: [PATCH] Don't panic because of invalid source --- src/cargo/core/source.rs | 2 +- tests/bad-config.rs | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/source.rs b/src/cargo/core/source.rs index ed684e954..4a46c1929 100644 --- a/src/cargo/core/source.rs +++ b/src/cargo/core/source.rs @@ -131,7 +131,7 @@ impl SourceId { pub fn from_url(string: &str) -> CargoResult { let mut parts = string.splitn(2, '+'); let kind = parts.next().unwrap(); - let url = parts.next().unwrap(); + let url = try!(parts.next().ok_or(human(format!("invalid source `{}`", string)))); match kind { "git" => { diff --git a/tests/bad-config.rs b/tests/bad-config.rs index ef1912d47..9e6aad274 100644 --- a/tests/bad-config.rs +++ b/tests/bad-config.rs @@ -280,6 +280,45 @@ Caused by: ")); } +#[test] +fn bad_source_in_cargo_lock() { + Package::new("foo", "0.1.0").publish(); + + let p = project("bar") + .file("Cargo.toml", r#" + [project] + name = "bar" + version = "0.0.1" + authors = [] + + [dependencies] + foo = "0.1.0" + "#) + .file("src/lib.rs", "") + .file("Cargo.lock", r#" + [root] + name = "bar" + version = "0.0.1" + dependencies = [ + "foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + ] + + [[package]] + name = "foo" + version = "0.1.0" + source = "You shall not parse" + "#); + p.build(); + + assert_that(p.cargo("build").arg("--verbose"), + execs().with_status(101).with_stderr("\ +[ERROR] failed to parse lock file at: [..] + +Caused by: + invalid source `You shall not parse` for the key `package.source` +")); +} + #[test] fn bad_git_dependency() { let foo = project("foo") -- 2.30.2